home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / general / procssng / ccs / ccs-11.lha / ccs-lib / tools / sun / sources / torast.c < prev   
Encoding:
C/C++ Source or Header  |  1993-04-15  |  3.1 KB  |  103 lines

  1. /*
  2. %    TORAST . C
  3. %
  4. %    convert others to SUN RASTer
  5. %
  6. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  7.  
  8. This software is copyright (C) by the Lawrence Berkeley Laboratory.
  9. Permission is granted to reproduce this software for non-commercial
  10. purposes provided that this notice is left intact.
  11.  
  12. It is acknowledged that the U.S. Government has rights to this software
  13. under Contract DE-AC03-765F00098 between the U.S.  Department of Energy
  14. and the University of California.
  15.  
  16. This software is provided as a professional and academic contribution
  17. for joint exchange. Thus, it is experimental, and is provided ``as is'',
  18. with no warranties of any kind whatsoever, no support, no promise of
  19. updates, or printed documentation. By using this software, you
  20. acknowledge that the Lawrence Berkeley Laboratory and Regents of the
  21. University of California shall have no liability with respect to the
  22. infringement of other copyrights by any part of this software.
  23.  
  24. For further information about this notice, contact William Johnston,
  25. Bld. 50B, Rm. 2239, Lawrence Berkeley Laboratory, Berkeley, CA, 94720.
  26. (wejohnston@lbl.gov)
  27.  
  28. For further information about this software, contact:
  29.     Jin Guojun
  30.     Bld. 50B, Rm. 2275, Lawrence Berkeley Laboratory, Berkeley, CA, 94720.
  31.     g_jin@lbl.gov
  32.  
  33. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  34. %
  35. % AUTHOR:    Jin Guojun - LBL    12/12/1991
  36. */
  37.  
  38. #include "header.def"
  39. #include "imagedef.h"
  40.  
  41. arg_fmt_list_string    arg_fmt[] =    {
  42.     {"-a", "%b", True, 1, 0, "add alpha channel"},
  43.     {"-8", "%+ %d", 256, 2, 0,
  44.         "quantizing to 8-bit with # colors [default # 256]"},
  45.     {"-d", "%-", No, 1, 0, "dither to 8"},
  46.     {"-k", "%b", True, 1, 0, "keep working, and ignore input error"},
  47.     {"-l", "%-", No, 1, 0, "rotate left 90"},
  48.     {"-r", "%+", No, 1, 0, "rotate right 90"},
  49.     {"-u", "%N", RT_STANDARD, 1, 0,
  50.         "use uncompress mode. The default is RLE"},
  51.     {"-o", "%s", No, 1, 1, "output file"},
  52.     {"    [<] input [[> | -o] output]", NULL, 0, 0, 0, "end of usage"},
  53.     NULL    };
  54. U_IMAGE    uimg;
  55. bool    rot, alpha, nostop, pr_t, to8, toN=256;
  56.  
  57. #define    rows    uimg.height
  58. #define    cols    uimg.width
  59.  
  60. main(ac, av)
  61. int    ac;
  62. char*    av[];
  63. {
  64. int    i;
  65. char    **fl, *of_name;
  66.  
  67.     if ((i=parse_argus(&fl, ac, av, arg_fmt,
  68.         &alpha, &to8, &toN, &to8,
  69.         &nostop, &rot, &rot, &pr_t, &of_name)) < 0)
  70.         exit(i);
  71.  
  72.     if (of_name && !(out_fp=freopen(av[++i], "wb", stdout)))
  73.         syserr("output file %s", of_name);
  74.     if (i && !(in_fp=freopen(uimg.name=fl[0], "rb", stdin)))
  75.         syserr("input %s", fl[0]);
  76.  
  77. uimg.color_dpy = alpha ? 1 : -1;
  78. format_init(&uimg, IMAGE_INIT_TYPE, RLE, RAS, *av, "A8-2");
  79.  
  80. io_test(fileno(in_fp), {parse_usage(arg_fmt); exit(0);});
  81.  
  82. if ((*uimg.header_handle)(HEADER_READ, &uimg, 0, 0, True))
  83.     syserr("unknown image type");
  84.  
  85. (*uimg.std_swif)(FI_LOAD_FILE, &uimg, nostop ? NULL : uimg.name, True);
  86.  
  87.     if (rot++) {
  88.     uimg.dest = uimg.src;
  89.     uimg.src = nzalloc(uimg.channels*uimg.width, uimg.height, "rot");
  90.     i = uimg.width;
  91.     uimg.width = uimg.height;
  92.     uimg.height = i;
  93.     color_rotate_90(uimg.dest, uimg.src, i, uimg.width,
  94.         uimg.color_form, rot);
  95.     free(uimg.dest);    uimg.dest = NULL;
  96.     }
  97.     if (uimg.channels>1 && to8)
  98.     To_8(&uimg, reg_cmap, to8>0, toN);
  99.  
  100. (*uimg.std_swif)(FI_SAVE_FILE, &uimg, pr_t, alpha);
  101. exit(0);
  102. }
  103.